package com.design.ticket;

import java.util.HashMap;
import java.util.Map;

public class TickeFactory {

    private static Map<String, Ticke> pool = new HashMap<>();

    public static Ticke queryTicke(String from, String to) {
        String key = from + "->" + to;
        if (pool.containsKey(key)) {
            System.out.println("使用缓存" + key);
            return pool.get(key);
        }
        System.out.println("首次查询,创建对象:" + key);
        Ticke ticke = new TrainTicke(from, to);
        pool.put(key, ticke);
        return ticke;
    }


}
